package com.book.helper;

import com.book.dto.OrderDetailDto;
import com.book.dto.OrderDto;
import com.book.dto.TempOrderBookDto;
import com.book.pojo.OrderBook;
import com.book.pojo.OrderDetail;
import com.book.pojo.TempOrder;
import org.springframework.beans.BeanUtils;

/**
 * @Author 李锦程
 * @Date 2021/4/26 10:24 下午
 * @Package com.book.helper
 * @Version 1.0
 */
public class OrderHelper {
    public static OrderDto covertPoDto(OrderBook book){
        if (book == null){
            return null;
        }
        OrderDto dto = new OrderDto();
        BeanUtils.copyProperties(book,dto);
        return dto;
    }

    public static OrderBook covertDtoPo(OrderDto dto){
        if (dto == null){
            return null;
        }
        OrderBook book = new OrderBook();
        BeanUtils.copyProperties(dto,book);
        return book;
    }

    public static OrderDetailDto covertDetailPoDto(OrderDetail detail){
        if (detail == null){
            return null;
        }
        OrderDetailDto detailDto = new OrderDetailDto();
        BeanUtils.copyProperties(detail,detailDto);
        return detailDto;
    }

    public static OrderDetail covertDetailPoDto(OrderDetailDto detailDto){
        if (detailDto == null){
            return null;
        }
        OrderDetail detail = new OrderDetail();
        BeanUtils.copyProperties(detailDto,detail);
        return detail;
    }

    public static TempOrder covertTempDtoToTempOrderPo(TempOrderBookDto dto){
        if (dto == null){
            return null;
        }
        TempOrder tempOrder = new TempOrder();
        tempOrder.setBookCode(dto.getBookCode());
        tempOrder.setBookTitle(dto.getBookName());
        tempOrder.setNum(dto.getNum());
        tempOrder.setImgUrl(dto.getImgUrl());
        tempOrder.setPrice(dto.getPrice());
        tempOrder.setBookAuthor(dto.getBookAuthor());
        tempOrder.setCate(dto.getCategory());
        tempOrder.setTotalPrice(dto.getTotalPrice());
        return tempOrder;
    }
}
